import Vue from 'vue'
import App from './App.vue'
import router from './router/index.js'
import axios from 'axios';
import 'github-markdown-css/github-markdown.css'
import hljs from 'highlight.js';
/* 样式文件需要自己导入 */
import 'highlight.js/styles/github.css';

import FontDetect from 'font-detect';

import VueClipboard from 'vue-clipboard2'

import myfont from '../public/myfont.css'


// if (localStorage.getItem('cacheIsIsdarkMode') != null) {
//   const link = document.createElement('link')
//   link.rel = 'stylesheet'
//   link.href = 'global.css'
//   document.head.appendChild(link)
//   document.documentElement.style.setProperty('--journal-edittar', '#454546');
//   document.documentElement.style.setProperty('--journal-edittar-placeholder', '#454546');

// }
// else {
//   document.documentElement.style.setProperty('--journal-edittar', '#ccc');

//   document.documentElement.style.setProperty('--journal-edittar-placeholder', 'rgba(0,0,0,.6)');
// }


let thisselectMybackground = localStorage.getItem('cacheSelectMybackground')

if (thisselectMybackground != null && thisselectMybackground != "") {

  if (thisselectMybackground != 'none') {
    //聊天框高度控制  有的38px 有的40px
    document.documentElement.style.setProperty('--markdown-body-min-height', '38px');

 
    const link = document.createElement('link')
    link.rel = 'stylesheet'
    link.href = 'global.css'
    document.head.appendChild(link)
    document.documentElement.style.setProperty('--global-background', thisselectMybackground); //全局背景色

    if (thisselectMybackground == '#191919' || thisselectMybackground == '#1f2029') //暗黑
    {
      document.documentElement.style.setProperty('--global-color', '#bbbbbb'); //全局字体颜色色

      if (thisselectMybackground == '#1f2029') {
        const link = document.createElement('link')
        link.rel = 'stylesheet'
        link.href = 'bgcblack.css'
        document.head.appendChild(link)
      }

    }
    else if (thisselectMybackground == '#2c2c2f') //沉浸棕
    {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = 'bgcbrown.css'
      document.head.appendChild(link)
      document.documentElement.style.setProperty('--global-color', '#acadae'); //全局字体颜色色
    }
    else if (thisselectMybackground == '#1e1e1e') //Vscode 模式
    {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = 'vscodemode.css'
      document.head.appendChild(link)
      document.documentElement.style.setProperty('--global-color', '#acadae'); 
    }
    else if (thisselectMybackground == '#1f1f1f') //浅黑模式
    {
      document.documentElement.style.setProperty('--global-color', '#acadae'); //全局字体颜色色
    }
    else if (thisselectMybackground == 'c7edcc') //护眼模式
    {
      document.documentElement.style.setProperty('--global-color', '#181818'); //全局字体颜色色
    }
    else if (thisselectMybackground == 'pink') //骚男
    {
      document.documentElement.style.setProperty('--global-color', '#181818'); //全局字体颜色色
    }


    document.documentElement.style.setProperty('--journal-edittar', '#454546');
    document.documentElement.style.setProperty('--journal-edittar-placeholder', '#454546');
  }
  else {
    // 简约模式
    document.documentElement.style.setProperty('--journal-edittar', '#e6e5e5');
    document.documentElement.style.setProperty('--journal-edittar-placeholder', 'rgba(0,0,0,.6)');

    //聊天框高度控制  有的38px 有的40px
    document.documentElement.style.setProperty('--markdown-body-min-height', '40px');
  }
}
else {
  // 简约模式
  document.documentElement.style.setProperty('--journal-edittar', '#e6e5e5');
  document.documentElement.style.setProperty('--journal-edittar-placeholder', 'rgba(0,0,0,.6)');

  //聊天框高度控制  有的38px 有的40px
  document.documentElement.style.setProperty('--markdown-body-min-height', '40px');
}





let thisselectMyFontfamily = localStorage.getItem('cacheSelectMyFontfamily')
if (thisselectMyFontfamily != null && thisselectMyFontfamily != "") {
  document.documentElement.style.setProperty('--global-fontfamily', thisselectMyFontfamily);
}
else {
  document.documentElement.style.setProperty('--global-fontfamily', 'KaiTi');
}






VueClipboard.config.autoSetContainer = true
Vue.config.productionTip = false
Vue.use(VueClipboard)

Vue.config.productionTip = false
Vue.prototype.axios = axios

Vue.prototype.$myWords = window.myWords

//Vue.prototype.$BaseUrl = 'http://localhost:7000'

Vue.prototype.$BaseUrl = 'https://api.xiaoshagua.top'





import { createSocket } from './Tools/websocket.js'
//createSocket('ws://127.0.1:5000')
createSocket('wss://scoket.xiaoshagua.top:5000')
// 发送消息
import { sendWSPush } from './Tools/websocket.js'

Vue.prototype.MyWebSockeSend = sendWSPush;

Vue.prototype.BaseUrl = ''

/* Vue.directive('heightConst', function (el) {
  const blocks = el.querySelectorAll('pre code')
  blocks.forEach(block => {
    hljs.highlightBlock(block)
  })
}) */

Vue.directive('focus', {
  inserted: function (el) {
    el.focus();
  }
});


import TopBar from "@/components/TopBar.vue";
Vue.component('TopBar', TopBar)

new Vue({
  router,
  render: h => h(App),
}).$mount('#app')
